package com.jing.weibo.init;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.jing.system.comm.contants.Contants;
import com.jing.system.comm.contants.DataCons;
import com.jing.system.comm.contants.RankingCons;
import com.jing.system.comm.contants.SystemCons;
import com.jing.system.comm.contants.TaobaoCons;
import com.jing.system.comm.contants.WeiboCons;
import com.jing.system.utils.SpringUtil;
import com.jing.system.utils.loadresource.LoadResourceUtil;
import com.jing.weibo.scheduler.task.TaskManager;

/**
 * 初始化系统数据的Servlet
 * @author jing.yue
 * @version 2012/08/29 1.0.0
 */
public class Init extends HttpServlet {

	private static final Logger logger = Logger.getLogger(Init.class);

	private static final long serialVersionUID = -2274726206362496315L;

	/**
     * @see HttpServlet#HttpServlet()
     */
    public Init() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * 初始化方法
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		logger.info("初始化数据中...");
		long startTime = System.currentTimeMillis();
		//初始化System常用信息
		SystemCons.initSystemData(config);

		//设置新浪常用数据到Application中
		WeiboCons.initWeiboData(config);

		//设置淘宝常用数据到Application中
		TaobaoCons.initTaobaoData(config);

		//初始化用户等级
		DataCons.initGradeMap(config);
		//初始化规则信息
		DataCons.initRuleMap(config);

		//初始化泡吧分区信息
		DataCons.initPbTypeMap(config, null);

		//初始化榜上有名的信息
		RankingCons.initRanking(config);

		//设置项目根目录的绝对路径
		SystemCons.ABSOLUTE_PATH = config.getServletContext().getRealPath("");

		Contants contants = (Contants) SpringUtil.getBean("contants");
		//初始化资源信息
		LoadResourceUtil.initLoadResource("loadresource/loadresource.xml", SystemCons.ABSOLUTE_PATH, contants.getJs_css_isPack());

		//添加定时Job
		/*TaskManager taskManager = (TaskManager) SpringUtil.getBean("taskManager");
		taskManager.addGetNewMpUserTask();*/

		//初始化资源花费时间
		logger.info("初始化资源花费" + (System.currentTimeMillis() - startTime) + "毫秒!");
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
